﻿//-----------------------------------------------------------------
//
// @(#)$Id: EbayPayPalRelevanceDetail.aspx.cs,v 1.0 2013/12/13 17:16:31 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:16:31 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_EbayTableAdapters;

public partial class UI_Bas_EbayPayPalRelevanceDetail : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        T_EbayAccountTableAdapter adapter = new T_EbayAccountTableAdapter();
        ddlEbayUserId.DataSource = adapter.GetData();
        ddlEbayUserId.DataTextField = "EbayUserId";
        ddlEbayUserId.DataBind();
        T_PayPalAccountTableAdapter paypalAdapter = new T_PayPalAccountTableAdapter();
        ddlPayPalUserId.DataSource = paypalAdapter.GetData();
        ddlPayPalUserId.DataTextField = "PayPalUserId";
        ddlPayPalUserId.DataBind();       
    }

    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {          
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        break;
                    case "U":
                        {
                            string PayPalUserId = Request.QueryString["id"];                           
                            T_EbayPaypalAccountRelationTableAdapter ebayAdapter = new T_EbayPaypalAccountRelationTableAdapter();
                            DataTable dt = ebayAdapter.GetDataByPayPalUserId(PayPalUserId);
                            DataRow r = dt.Rows[0];
                            ddlEbayUserId.Text = r["EbayUserId"].ToString();
                            ddlPayPalUserId.Text = r["PayPalUserId"].ToString();
                            txtMnote.Value = r["Mnote"].ToString();
                            ddlPayPalUserId.Enabled = false;
                        }
                        break;
                }
            }
        }
    }
   
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        string userId = Session["UserId"].ToString();

        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        T_EbayPaypalAccountRelationTableAdapter ebayAdapter = new T_EbayPaypalAccountRelationTableAdapter();
                        int falg = int.Parse(ebayAdapter.IsExists(ddlPayPalUserId.SelectedValue).ToString ());
                        if (falg ==0)
                        {
                            int val = ebayAdapter.Insert(
                                     ddlPayPalUserId.SelectedValue,
                                     ddlEbayUserId.SelectedValue,
                                     txtMnote.Value,
                                     userId,
                                     DateTime.Now,
                                     "",
                                     new DateTime(1900, 1, 1));
                            if (val > 0)
                            {
                                Response.Write("<script>alert('添加成功!');window.location.href='EbayPayPalRelevance.aspx'</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert('此PayPal帐号已经关联Ebay帐号!');</script>");
                        }
                    }
                    break;
                case "U":
                    {
                        string PayPalUserId = Request.QueryString["id"]; 
                        T_EbayPaypalAccountRelationTableAdapter ebayAdapter = new T_EbayPaypalAccountRelationTableAdapter();                        
                        int val = ebayAdapter.Update(
                                  ddlEbayUserId.SelectedValue,
                                  txtMnote.Value,
                                  userId,
                                  DateTime.Now,
                                  "",
                                  new DateTime(1900, 1, 1),
                                  PayPalUserId);
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='EbayPayPalRelevance.aspx'</script>");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
